_GLOBAL_FILE_CONTENT = "";
_GLOBAL_ID = "";
function createSaveFileDiv(content, id) {
    _GLOBAL_FILE_CONTENT = content;
    _GLOBAL_ID = id;
    var div = document.createElement("div");
    div.id = "SaveFile";
    div.innerHTML = "<h3> &nbsp&nbspSave</h3><hr/>";
    var div2 = document.createElement("div");
    div2.style.height = "310";
    div2.style.overflow = "auto";
    
    div2.innerHTML = '<form>' + 
                     '&nbsp&nbspFilename: &nbsp&nbsp<input type="text" id="filename" /><br />' +
                     '&nbsp&nbspFilepath: <input type="text" id="filepath" />' +
                     '</form>';
    
    for (var j = 10; j > 0; j--)
		div2.innerHTML = div2.innerHTML + "&nbsp";
    var moreButton = document.createElement('input');
    moreButton.type = 'button';
    moreButton.value = "    Save File    ";
    moreButton.name = "Save";
    moreButton.setAttribute("onclick", "unique_saveFile()");
    div2.appendChild(moreButton);
    var cancelButton = document.createElement('input');
    cancelButton.type = 'button';
    cancelButton.value = "   cancel   ";
    cancelButton.name = "cancelbutton";
    cancelButton.setAttribute("onclick", "cancelSaveFile()");
    div2.appendChild(cancelButton);
    
	div.appendChild(div2);
    div.appendChild(document.createElement('br'));
    div.appendChild(document.createElement('br'));
    div.appendChild(document.createElement('br'));
    div.appendChild(document.createElement('br'));
    document.body.appendChild(div);
}

function unique_saveFile() {
    var filename = document.getElementById("filename").value;
    var filepath = document.getElementById("filepath").value;
    if (filename == '' || filepath == '')
        alert("Account or Password is empty!");
    else 
	  {
		   //alert(filename);
		   //alert(filepath);
		   //alert(_GLOBAL_FILE_CONTENT);
		  
		  saveFile(filepath, _GLOBAL_FILE_CONTENT, filename);
		  var titleDOM = domtab.getTitle(_GLOBAL_ID);
		  
		  titleDOM.setAttribute("name", filename);
		  titleDOM.setAttribute("title", filename);
		  titleDOM.setAttribute("path", filepath);
		  
		  console.log(titleDOM);
	    var titleHTML = titleDOM.innerHTML;
	    titleDOM.innerHTML = filename;
	    //console.log(titleDOM.innerHTML);
	    titleDOM.setAttribute("status", "UNCHANGED");
	    fileTreeRefresh();
	  }
    cancelSaveFile();
}

function cancelSaveFile() {
	var div = document.getElementById("SaveFile");
	document.body.removeChild(div);
}
